package com.example.demo.config;



import com.alibaba.fastjson.JSON;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.*;

public class SignTools {

    /**
     *得到签名内容
     * @param sortedParams
     * @return
     */
    public static String getSignContentMap(Map<String, Object> sortedParams, String secretKey) {
        StringBuffer content = new StringBuffer();
        List<String> keys = new ArrayList(sortedParams.keySet());
        Collections.sort(keys);
        int index = 0;

        for(int i = 0; i < keys.size(); ++i) {
            String key = (String)keys.get(i);
            Object value = sortedParams.get(key);
            if (value != null && String.valueOf(value).length() > 0) {
                content.append((index == 0 ? "" : "&") + key + "=" + value);
                ++index;
            }
        }

        content.append("&key=" + secretKey);
        return content.toString();
    }


    }


